<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>个人博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="个人博客">
<meta property="og:url" content="http://codercheng.cn/page/2/index.html">
<meta property="og:site_name" content="个人博客">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="CoderCheng">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="个人博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.lug.ustc.edu.cn/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 4.2.1"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">个人博客</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://codercheng.cn"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-笔记" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/04/30/%E7%AC%94%E8%AE%B0/" class="article-date">
  <time datetime="2021-04-30T02:36:54.716Z" itemprop="datePublished">2021-04-30</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2021/04/30/%E7%AC%94%E8%AE%B0/">笔记</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="开发实战及解决方案-笔记"><a href="#开发实战及解决方案-笔记" class="headerlink" title="开发实战及解决方案 笔记"></a>开发实战及解决方案 笔记</h1><h2 id="1-系统简介"><a href="#1-系统简介" class="headerlink" title="1. 系统简介"></a>1. 系统简介</h2><p>系统架构</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/30/102757-476885.png" alt="系统架构"></p>
<p>服务间关系</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/30/102801-865139.png" alt="服务关系"></p>
<h2 id="2-单点登录及第三方登录解决方案"><a href="#2-单点登录及第三方登录解决方案" class="headerlink" title="2. 单点登录及第三方登录解决方案"></a>2. 单点登录及第三方登录解决方案</h2><p>token生成流程</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/30/102805-808807.png" alt="token生成流程"></p>
<p>微信登录流程</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/30/102809-571094.png" alt="微信登录流程"></p>
<h2 id="3-第三方支付"><a href="#3-第三方支付" class="headerlink" title="3. 第三方支付"></a>3. 第三方支付</h2><p>支付宝</p>
<p><a href="https://opendocs.alipay.com/apis/api_1/alipay.trade.precreate" target="_blank" rel="noopener">https://opendocs.alipay.com/apis/api_1/alipay.trade.precreate</a> </p>
<p>微信支付</p>
<p><a href="https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/Overview.shtml" target="_blank" rel="noopener">https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/Overview.shtml</a></p>
<h2 id="4-秒杀"><a href="#4-秒杀" class="headerlink" title="4. 秒杀"></a>4. 秒杀</h2><p>后台发布秒杀活动课程信息</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/30/102811-727993.png" alt="后台发布秒杀活动课程信息"></p>
<p>前端用户抢购课程</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/30/102813-423678.png" alt="前端用户抢购课程"></p>
<p>超时未支付流程</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/30/102815-960784.png" alt="超时未支付流程"></p>
<h2 id="5-分布式事务解决方案-Seata"><a href="#5-分布式事务解决方案-Seata" class="headerlink" title="5. 分布式事务解决方案 Seata"></a>5. 分布式事务解决方案 Seata</h2><p>Seata 是一款开源的分布式事务解决方案，致力于提供高性能和简单易用的分布式事务服 </p>
<p>务。 Seata 将为用户提供了 AT、TCC、SAGA 和 XA 事务模式，为用户打造一站式的分布式解决方案。 </p>
<p>官方文档地址：<a href="https://seata.io/zh-cn/index.html" target="_blank" rel="noopener">https://seata.io/zh-cn/index.html</a></p>
<p>Seata 下载地址：<a href="https://seata.io/zh-cn/docs/ops/deploy-guide-beginner.html" target="_blank" rel="noopener">https://seata.io/zh-cn/docs/ops/deploy-guide-beginner.html</a></p>
<p> 视频加密流程</p>
<p><img src="/.cn//C:%5CUsers%5CLenovo%5CDesktop%5C%E6%8B%89%E5%8B%BE%5C%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99%5C%E7%AC%AC%E5%8D%81%E4%B8%80%E9%98%B6%E6%AE%B5%5C%E9%A1%B9%E7%9B%AE%E8%B5%84%E6%96%99%5C%E9%A1%B9%E7%9B%AE%E8%B5%84%E6%96%99%5C%E8%AE%B2%E4%B9%89%5Cmd%E5%9B%BE%E7%89%87%5Cimage-20200918170348950.png" alt="image-20200918170348950"></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://codercheng.cn/2021/04/30/%E7%AC%94%E8%AE%B0/" data-id="cko3snvxd001ii8uodcw29zu9" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-11-1" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/04/30/11-1/" class="article-date">
  <time datetime="2021-04-30T02:24:50.121Z" itemprop="datePublished">2021-04-30</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2021/04/30/11-1/">11-1</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>​                             系统架构</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/30/102342-582466.png" alt="系统架构"></p>
<p>​                                                          服务关系</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/30/102355-838308.png" alt></p>
<p>   视频加密过程</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/30/102652-586229.png" alt="image-20200918170348950"></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://codercheng.cn/2021/04/30/11-1/" data-id="cko3snvw60001i8uodayc99o7" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-作业" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/04/27/%E4%BD%9C%E4%B8%9A/" class="article-date">
  <time datetime="2021-04-27T06:42:16.527Z" itemprop="datePublished">2021-04-27</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2021/04/27/%E4%BD%9C%E4%B8%9A/">作业</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="作业"><a href="#作业" class="headerlink" title="作业"></a>作业</h3><h3 id="1-、-什么是CAS"><a href="#1-、-什么是CAS" class="headerlink" title="1 、 什么是CAS"></a>1 、 什么是CAS</h3><p>  CAS是英文单词CompareAndSwap的缩写，中文意思是：比较并替换。CAS需要有3个操作数：内存地址V，旧的预期值A，即将要更新的目标值B。CAS指令执行时，当且仅当内存地址V的值与预期值A相等时，将内存地址V的值修改为B，否则就什么都不做。整个比较并替换的操作是一个原子操作。CAS是乐观锁技术，当多个线程尝试使用CAS同时更新同一个变量时，只有其中一个线程能更新变量的值，而其它线程都失败，失败的线程并不会被挂起，而是被告知这次竞争中失败，并可以再次尝试</p>
<h3 id="2、CyclicBarrier和CountDownLatch区别"><a href="#2、CyclicBarrier和CountDownLatch区别" class="headerlink" title="2、CyclicBarrier和CountDownLatch区别"></a>2、CyclicBarrier和CountDownLatch区别</h3><p>​              CyclicBarrier是一种同步机制允许一组线程相互等待，等到所有线程都到达一个屏障点才退出await方法，它没有直接实现AQS而是借助ReentrantLock来实现的同步机制。它是可循环使用的，而CountDownLatch是一次性的，另外它体现的语义也跟CountDownLatch不同，CountDownLatch减少计数到达条件采用的是release方式，而CyclicBarrier走向屏障点（await）采用的是Acquire方式，Acquire是会阻塞的，这也实现了CyclicBarrier的另外一个特点，只要有一个线程中断那么屏障点就被打破，所有线程都将被唤醒（CyclicBarrier自己负责这部分实现，不是由AQS调度的），这样也避免了因为一个线程中断引起永远不能到达屏障点而导致其他线程一直等待。屏障点被打破的CyclicBarrier将不可再使用（会抛出BrokenBarrierException）除非执行reset操作</p>
<h3 id="3、volatile关键字的作用"><a href="#3、volatile关键字的作用" class="headerlink" title="3、volatile关键字的作用"></a>3、volatile关键字的作用</h3><p>作用：保证被修饰变量的内存可见性，用volatile修饰的变量，线程在每次使用变量的时候，都会读取变量修改后的最新的值。</p>
<h3 id="4-、如何正确的使用wait-使用if还是while？"><a href="#4-、如何正确的使用wait-使用if还是while？" class="headerlink" title="4 、如何正确的使用wait()?使用if还是while？"></a>4 、如何正确的使用wait()?使用if还是while？</h3><p> wait() 方法应该在循环调用，因为当线程获取到 CPU 开始执行的时候，其他条件可能还没有满足，所以在处理前，循环检测条件是否满足会更好</p>
<h3 id="5-、为什么wait、nofity和nofityAll这些方法不放在Thread类当中"><a href="#5-、为什么wait、nofity和nofityAll这些方法不放在Thread类当中" class="headerlink" title="5  、为什么wait、nofity和nofityAll这些方法不放在Thread类当中"></a>5  、为什么wait、nofity和nofityAll这些方法不放在Thread类当中</h3><p>JAVA提供的锁是对象级的而不是线程级的，每个对象都有锁，通过线程获得。如果线程需要等待某些锁那么调用对象中的wait()方法就有意义了。如果wait()方法定义在Thread类中，线程正在等待的是哪个锁就不明显了。简单的说，由于wait，notify和notifyAll都是锁级别的操作，所以把他们定义在Object类中因为锁属于对象。</p>
<h3 id="6、synchronized和ReentrantLock的区别"><a href="#6、synchronized和ReentrantLock的区别" class="headerlink" title="6、synchronized和ReentrantLock的区别"></a>6、synchronized和ReentrantLock的区别</h3><p>相似点： 这两种同步方式有很多相似之处，它们都是加锁方式同步，而且都是阻塞式的同步，也就是说当如果一个线程获得了对象锁，进入了同步块，其他访问该同步块的线程都必须阻塞在同步块外面等待，而进行线程阻塞和唤醒的代价是比较高的（操作系统需要在用户态与内核态之间来回切换，代价很高，不过可以通过对锁优化进行改善）。 功能区别： 这两种方式最大区别就是对于Synchronized来说，它是java语言的关键字，是原生语法层面的互斥，需要jvm实现。而ReentrantLock它是JDK 1.5之后提供的API层面的互斥锁，需要lock()和unlock()方法配合try/finally语句块来完成 便利性：很明显Synchronized的使用比较方便简洁，并且由编译器去保证锁的加锁和释放，而ReenTrantLock需要手工声明来加锁和释放锁，为了避免忘记手工释放锁造成死锁，所以最好在finally中声明释放锁。 锁的细粒度和灵活度：很明显ReenTrantLock优于Synchronized 性能的区别： 在Synchronized优化以前，synchronized的性能是比ReenTrantLock差很多的，但是自从Synchronized引入了偏向锁，轻量级锁（自旋锁）后，两者的性能就差不多了，在两种方法都可用的情况下，官方甚至建议使用synchronized，其实synchronized的优化我感觉就借鉴了ReenTrantLock中的CAS技术。都是试图在用户态就把加锁问题解决，避免进入内核态的线程阻塞。</p>
<h3 id="7、什么是AQS"><a href="#7、什么是AQS" class="headerlink" title="7、什么是AQS"></a>7、什么是AQS</h3><p>AQS，即AbstractQueuedSynchronizer, 队列同步器，它是Java并发用来构建锁和其他同步组件的基础框架。AQS是一个抽象类，主是是以继承的方式使用。AQS本身是没有实现任何同步接口的，它仅仅只是定义了同步状态的获取和释放的方法来供自定义的同步组件的使用。</p>
<h3 id="8、什么是Java内存模型"><a href="#8、什么是Java内存模型" class="headerlink" title="8、什么是Java内存模型"></a>8、什么是Java内存模型</h3><p><a href="https://www.yuque.com/docs/share/1075cf31-8b7d-42c2-803d-e3307aca851f?#" target="_blank" rel="noopener">https://www.yuque.com/docs/share/1075cf31-8b7d-42c2-803d-e3307aca851f?#</a> 《Java内存模型》</p>
<h3 id="9、什么是自旋"><a href="#9、什么是自旋" class="headerlink" title="9、什么是自旋"></a>9、什么是自旋</h3><p>是指当一个线程在获取锁的时候，如果锁已经被其它线程获取，那么该线程将循环等待，然后不断的判断锁是否能够被成功获取，直到获取到锁才会退出循环。</p>
<h3 id="10、Java编程写一个会导致死锁的程序"><a href="#10、Java编程写一个会导致死锁的程序" class="headerlink" title="10、Java编程写一个会导致死锁的程序"></a>10、Java编程写一个会导致死锁的程序</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DeadLock</span> <span class="keyword">implements</span> <span class="title">Runnable</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">int</span> flag;</span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">DeadLock</span><span class="params">(<span class="keyword">int</span> flag)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.flag = flag;</span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line">    <span class="keyword">static</span> Object lock1 = <span class="keyword">new</span> Object();</span><br><span class="line">    <span class="keyword">static</span> Object lock2 = <span class="keyword">new</span> Object();</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span> </span>&#123;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">if</span> (flag == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">synchronized</span> (lock1) &#123;</span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line">                    System.out.println(<span class="string">"线程："</span> + Thread.currentThread().getName() + <span class="string">"已获得锁"</span> + lock1);</span><br><span class="line">                    Thread.sleep(<span class="number">500</span>);</span><br><span class="line">                &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">                    e.printStackTrace();</span><br><span class="line">                &#125;</span><br><span class="line">                System.out.println(<span class="string">"线程："</span> + Thread.currentThread().getName() + <span class="string">"等待获得锁"</span> + lock2);</span><br><span class="line">                <span class="keyword">synchronized</span> (lock2) &#123;</span><br><span class="line">                    System.out.println(<span class="string">"线程："</span> + Thread.currentThread().getName() + <span class="string">"已获得锁"</span> + lock2);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (flag == <span class="number">1</span>) &#123;</span><br><span class="line"> </span><br><span class="line">            <span class="keyword">synchronized</span> (lock2) &#123;</span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line">                    System.out.println(<span class="string">"线程："</span> + Thread.currentThread().getName() + <span class="string">"已获得锁"</span> + lock2);</span><br><span class="line">                    Thread.sleep(<span class="number">500</span>);</span><br><span class="line">                &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">                    e.printStackTrace();</span><br><span class="line">                &#125;</span><br><span class="line">                System.out.println(<span class="string">"线程："</span> + Thread.currentThread().getName() + <span class="string">"等待获得锁"</span> + lock1);</span><br><span class="line">                <span class="keyword">synchronized</span> (lock1) &#123;</span><br><span class="line">                    System.out.println(<span class="string">"线程："</span> + Thread.currentThread().getName() + <span class="string">"已获得锁"</span> + lock1);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        DeadLock test1 = <span class="keyword">new</span> DeadLock(<span class="number">0</span>);</span><br><span class="line">        DeadLock test2 = <span class="keyword">new</span> DeadLock(<span class="number">1</span>);</span><br><span class="line">        Thread thread1 = <span class="keyword">new</span> Thread(test1);</span><br><span class="line">        Thread thread2 = <span class="keyword">new</span> Thread(test2);</span><br><span class="line">        thread1.start();</span><br><span class="line">        thread2.start();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://codercheng.cn/2021/04/27/%E4%BD%9C%E4%B8%9A/" data-id="cko3snvxa001di8uo4n9l23kc" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-并发编程" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/04/12/%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B/" class="article-date">
  <time datetime="2021-04-12T10:12:49.836Z" itemprop="datePublished">2021-04-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2021/04/12/%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B/">并发编程</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>​                             并发编程</p>
<p>AQS（AbstractQueuedSynchronizer）翻译为抽象队列同步器，是除Synchronized关键字外java自带的锁机制。</p>
<p>AQS使用一个int类型变量state来表示线程要竞争的资源，state的值即为可获取的资源数，当一个线程尝试获取锁时，会使用CAS方式去尝试改变state的值，如果改变成功，即获取了锁。CAS的实现是使用了Unsafe类底下的一系列compareAndSet*方法，这些方法调用了JAVA的native方法，可以认为是系统底层支持的原子操作.</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://codercheng.cn/2021/04/12/%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B/" data-id="cko3snvxd001ji8uohmoq3fj7" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-判断数组是否有重复数字 时间复杂度O(n)" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/04/09/%E5%88%A4%E6%96%AD%E6%95%B0%E7%BB%84%E6%98%AF%E5%90%A6%E6%9C%89%E9%87%8D%E5%A4%8D%E6%95%B0%E5%AD%97%20%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6O(n)/" class="article-date">
  <time datetime="2021-04-09T02:42:11.193Z" itemprop="datePublished">2021-04-09</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2021/04/09/%E5%88%A4%E6%96%AD%E6%95%B0%E7%BB%84%E6%98%AF%E5%90%A6%E6%9C%89%E9%87%8D%E5%A4%8D%E6%95%B0%E5%AD%97%20%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6O(n)/">判断数组是否有重复数字 时间复杂度O(n)</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>   判断数组是否有重复数字 时间复杂度O(n)</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/09/104023-706884.png" alt="image-20210409104021987"></p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/09/104041-149612.png" alt="image-20210409104041180"></p>
<p>   挖矿问题  使用动态规划 </p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/09/104146-675271.png" alt="image-20210409104145566"></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://codercheng.cn/2021/04/09/%E5%88%A4%E6%96%AD%E6%95%B0%E7%BB%84%E6%98%AF%E5%90%A6%E6%9C%89%E9%87%8D%E5%A4%8D%E6%95%B0%E5%AD%97%20%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6O(n)/" data-id="cko3snvx9001bi8uofipr92g3" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-数据结构与算法 学习笔记" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/04/08/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95%20%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="article-date">
  <time datetime="2021-04-08T05:41:46.308Z" itemprop="datePublished">2021-04-08</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2021/04/08/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95%20%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">数据结构与算法 学习笔记</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>​                                                    数据结构与算法 学习笔记</p>
<p>概念</p>
<p>  数据结构是计算机存储和组织数据的方式。数据结构是指相互之间存在一种或多种特定关系的数据元素的集合。</p>
<p>常见的数据结构</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/08/115715-115914.png" alt="image-20210408115710630"></p>
<p> <strong>算法</strong></p>
<p>概念</p>
<p>算法是指解题方案的准确而完整的描述，是一系列解决问题的清晰指令，算法代表着用系统的方法描述解决问题的策略机制。</p>
<p><strong>算法是一种解决特定问题的思路。</strong></p>
<p>常见的算法</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/08/133929-579057.png" alt="image-20210408133918634"></p>
<p>算法复杂度</p>
<p>我们采用时间复杂度和空间复杂度来计算</p>
<p><strong>时间复杂度</strong></p>
<p>T(n)=O(f(n)) </p>
<p><strong>空间复杂度</strong></p>
<p>空间复杂度全称是渐进空间复杂度，表示算法的存储空间与数据规模之间的增长关系</p>
<p>比如将一个数组拷贝到另一个数组中，就是相当于空间扩大了一倍:T(n)=O(2n)，忽略系数即为O(n)</p>
<p><strong>线性表</strong></p>
<p>线性表（Linear List）就是数据排成像一条线一样的结构，数据只有前后两个方向</p>
<p><strong>数组</strong>（Array）是有限个相同类型的变量所组成的有序集合，数组中的每一个变量被称为元素。数组是最为简单、最为常用的数据结构</p>
<p>应用</p>
<p>数组是基础的数据结构，应用太广泛了，ArrayList、Redis、消息队列等等。</p>
<p><strong>链表（</strong>linked list）是一种在物理上非连续、非顺序的数据结构，由若干节点（node）所组成。</p>
<p>链表中数据元素的逻辑顺序是通过链表中的指针链接次序实现的。链表由一系列结点（链表中每一个元素称为结点）组成，结点可以在运行时动态生成。每个结包括两个部分：一个是存储数据元素的数据域，另一个是存储下一个结点地址的指针域。（百度百科）</p>
<p>常见的链表包括：单链表、双向链表、循环链表</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/08/134434-109227.png" alt="image-20210408134425525"></p>
<p>数组和链表是线性数据存储的物理存储结构：即顺序存储和链式存储。</p>
<p><strong>栈和队列都属于线性数据的逻辑存储结构</strong></p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/08/134528-921660.png" alt="image-20210408134511941"></p>
<p><strong>栈</strong>（stack）是一种线性数据结构，栈中的元素只能先入后出（First In Last Out，简称FILO）。</p>
<p>最早进入的元素存放的位置叫作栈底（bottom），最后进入的元素存放的位置叫作栈顶 （top）。</p>
<p><strong>队列</strong></p>
<p>队列（queue）是一种线性数据结构，队列中的元素只能先入先出（First In First Out，简称 FIFO）。队列的出口端叫作队头（front），队列的入口端叫作队尾（rear）。</p>
<p><strong>散列表</strong></p>
<p>散列表也叫作哈希表（hash table），这种数据结构提供了键（Key）和值（Value）的映射关系。只要</p>
<p>给出一个Key，就可以高效查找到它所匹配的Value，时间复杂度接近于O(1)。</p>
<p><strong>存储原理</strong></p>
<p><strong>哈希函数</strong></p>
<p>散列表在本质上也是一个<strong>数组</strong> 散列表的Key则是以字符串类型为主的通过hash函数把Key和数组下标进行转换</p>
<p>作用是把任意长度的输入通过散列算法转换成固定类型、固定长度的散列值。</p>
<p>递归，去的过程叫”递”，回来的过程叫”归</p>
<p><strong>递归三要素</strong></p>
<ul>
<li><p>递归结束条件</p>
</li>
<li><p>函数的功能 </p>
<p>这个函数要干什么，打印，计算</p>
</li>
<li><p>函数的等价关系式</p>
<p>递归公式，一般是每次执行之间，或者与个数之间的逻辑关系</p>
</li>
</ul>
<p><strong>二分查找</strong></p>
<p>二分查找（Binary Search）算法，也叫折半查找算法</p>
<p>有很多数据的逻辑关系并不是线性关系，在实际场景中，常常存在着一对多，甚至是多对多的情况。家谱</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/08/135241-268517.png" alt="image-20210408135241370"></p>
<p><strong>二叉树</strong></p>
<p>二叉树（binary tree）是树的一种特殊形式。二叉，顾名思义，这种树的每个节点最多有2个孩子节点。注意，这里是最多有2个，也可能只有1个，或者没有孩子节点</p>
<p><strong>二叉查找树</strong></p>
<p>二叉查找树(binary search tree)，二叉查找树在二叉树的基础上增加了以下几个条件</p>
<p>如果左子树不为空，则左子树上所有节点的值均小于根节点的值</p>
<p>如果右子树不为空，则右子树上所有节点的值均大于根节点的值</p>
<p>左、右子树也都是二叉查找树</p>
<p> <strong>广度优先遍历（BFS，Breadth First Search）</strong></p>
<p>也叫层序遍历，顾名思义，就是二叉树按照从根节点到叶子节点的层次关系，一层一层横向遍历各个节点。</p>
<p><strong>深度优先搜索（DFS   Depth First Search）</strong></p>
<p>深度优先搜索，从起点出发，从规定的方向中选择其中一个不断地向前走，直到无法继续为止，然后尝</p>
<p>试另外一种方向，直到最后走到终点。就像走迷宫一样，尽量往深处走。</p>
<p>二叉查找树的插入和查找时间复杂度为:O(logn)</p>
<p>极端情况下二叉查找树退化成链表，时间复杂度为O(n)，所以需要平衡二叉查找树。</p>
<p><strong>红黑树</strong></p>
<p>红黑树就是一种自平衡的二叉查找树</p>
<p>除了二叉查找树(BST)的特征外，还有以下特征：</p>
<p>每个节点要么是黑色，要么是红色</p>
<p>根节点是黑色</p>
<p>每个叶子节点都是黑色的空结点（NIL结点）（为了简单期间，一般会省略该节点）</p>
<p>如果一个节点是红色的，则它的子节点必须是黑色的（父子不能同为红）</p>
<p>从任一结点到其每个叶子的所有路径都包含相同数目的黑色结点（平衡的关键）</p>
<p>新插入节点默认为红色，插入后需要校验红黑树是否符合规则，不符合则需要进行平衡</p>
<p><strong>多路查找树</strong></p>
<p>*<em>多路查找树(muitl-way search tree)，其每一个节点的孩子数可以多于两个，且每一个节点处可以存储多个元素 *</em> 。</p>
<p>B树（BalanceTree）是对二叉查找树的改进。它的设计思想是，将相关数据尽量集中在一起，以便一</p>
<p>次读取多个数据，减少硬盘操作次数</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/08/140121-568635.png" alt="image-20210408140120320"></p>
<p>B+树是B-树的变体，也是一种多路搜索树，其定义基本与B树相同，它的自身特征是：</p>
<p>非叶子结点的子树指针与关键字个数相同</p>
<p>非叶子结点的子树指针P[i]，指向关键字值属于[K[i], K[i+1])的子树</p>
<p>所有关键字都在叶子结点出现</p>
<p>为所有叶子结点增加一个链指针</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202104/08/140135-774082.png" alt="image-20210408140134258"></p>
<p><strong>典型应用</strong></p>
<p>MySQL索引B+Tree</p>
<p>B树是为了磁盘或其它存储设备而设计的一种多叉（下面你会看到，相对于二叉，B树每个内结点有多个</p>
<p>分支，即多叉）平衡查找树。 多叉平衡</p>
<p>B树的高度一般都是在2-4这个高度，树的高度直接影响IO读写的次数。</p>
<p>如果是三层树结构—支撑的数据可以达到20G，如果是四层树结构—支撑的数据可以达到几十T </p>
<p>B和B+的区别</p>
<p>B树和B+树的最大区别在于<strong>非叶子节点是否存储数据</strong>的问题。</p>
<p><strong>二叉堆</strong></p>
<p>二叉堆本质上是一种完全二叉树，它分为两个类型</p>
<p>大顶堆(最大堆)</p>
<p>最大堆的任何一个父节点的值，都大于或等于它左、右孩子节点的值</p>
<p>小顶堆(最小堆)</p>
<p>最小堆的任何一个父节点的值，都小于或等于它左、右孩子节点的值</p>
<p><strong>算法思维</strong></p>
<p><strong>贪婪算法</strong>（Greedy）的定义：是一种在每一步选中都采取在当前状态下最好或最优的选择，从而希望</p>
<p>导致结果是全局最好或最优的算法</p>
<p>贪婪算法：当下做局部最优判断，不能回退</p>
<p><strong>经典问题</strong></p>
<p><strong>部分背包问题</strong></p>
<p><strong>适用场景</strong></p>
<p>针对一组数据，我们定义了限制值和期望值，希望从中选出几个数据，在满足限制值的情况下，期望值</p>
<p>最大。</p>
<p><strong>分治算法</strong></p>
<p>分治算法（divide and conquer）的核心思想其实就是四个字，分而治之 ，也就是将原问题划分成 n</p>
<p>个规模较小，并且结构与原问题相似的子问题，递归地解决这些子问题，然后再合并其结果，就得到原</p>
<p>问题的解。</p>
<p>关于分治和递归的区别</p>
<p>分治算法是一种处理问题的思想，递归是一种编程技巧</p>
<p><strong>经典问题</strong></p>
<p><strong>字符串转大写</strong></p>
<p><strong>回溯算法</strong></p>
<p>回溯算法实际上一个类似枚举的深度优先搜索尝试过程，主要是在搜索尝试过程中寻找问题的解，当发</p>
<p>现已不满足求解条件时，就“回溯”返回（也就是递归返回），尝试别的路径</p>
<p><strong>经典问题                 N皇后问题</strong></p>
<p><strong>动态规划</strong></p>
<p>动态规划(Dynamic Programming)，是一种分阶段求解的方法。</p>
<p>动态规划算法是通过拆分问题，定义问题状态和状态之间的关系，使得问题能够以递推（或者说分治）</p>
<p>的方式去解决。</p>
<p>动态规划中有三个重要概念：</p>
<ul>
<li><p>最优子结构</p>
</li>
<li><p>边界</p>
</li>
<li><p>状态转移公式（递推方程）dp方程</p>
</li>
</ul>
<p><strong>经典问题             01 背包问题</strong></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://codercheng.cn/2021/04/08/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95%20%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" data-id="cko3snvxm001ui8uo88ic4z1k" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-k8s" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/03/31/k8s/" class="article-date">
  <time datetime="2021-03-31T05:33:48.469Z" itemprop="datePublished">2021-03-31</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2021/03/31/k8s/">k8s</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>​                      </p>
<p>​                                         Kubernetes 学习笔记</p>
<p> 常用命令</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">查看default命名空间下的pods</span><br><span class="line">kubectl get pods</span><br><span class="line">查看kube<span class="literal">-system</span>命名空间下的pods</span><br><span class="line">kubectl get pods <span class="literal">-n</span> kube<span class="literal">-system</span></span><br><span class="line">查看所有命名空间下的pods</span><br><span class="line">kubectl get pod -<span class="literal">-all</span><span class="literal">-namespaces</span></span><br><span class="line">kubectl get pod <span class="literal">-A</span></span><br><span class="line">以纯文本输出格式列出所有pod ,并包含附加信息(如节点名)</span><br><span class="line">kubectl get pods <span class="literal">-o</span> wide</span><br></pre></td></tr></table></figure>

<p><strong>运行pod</strong></p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">在default命名空间中创建一个pod副本的deployment</span><br><span class="line">kubectl run tomcat9<span class="literal">-test</span> -<span class="literal">-image</span>=tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre</span><span class="literal">-alpine</span> -<span class="literal">-port</span>=<span class="number">8080</span></span><br><span class="line">kubectl get pod</span><br><span class="line">kubectl get pod <span class="literal">-o</span> wide</span><br></pre></td></tr></table></figure>

<p><strong>扩容</strong></p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">kubectl scale -<span class="literal">-replicas</span>=<span class="number">3</span> deployment/tomcat9<span class="literal">-test</span></span><br><span class="line">kubectl get deployment</span><br><span class="line">kubectl get deployment <span class="literal">-o</span> wide</span><br></pre></td></tr></table></figure>

<p><strong>创建服务</strong></p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">kubectl expose deployment tomcat9<span class="literal">-test</span> -<span class="literal">-name</span>=tomcat9<span class="literal">-svc</span> -<span class="literal">-port</span>=<span class="number">8888</span> -<span class="literal">-target</span><span class="literal">-port</span>=<span class="number">8080</span> -<span class="literal">-protocol</span>=TCP -<span class="literal">-type</span>=NodePort</span><br><span class="line">kubectl get svc </span><br><span class="line">kubectl get svc <span class="literal">-o</span> wide</span><br></pre></td></tr></table></figure>

<p><strong>delete 命令</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">kubectl delete -f pod.yaml </span><br><span class="line"> 删除所有 pod，包括未初始化的 pod</span><br><span class="line"> kubectl delete pods --all</span><br></pre></td></tr></table></figure>

<p><strong>进入容器</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kubectl exec -ti &lt;pod-name&gt; &#x2F;bin&#x2F;bash</span><br></pre></td></tr></table></figure>



<p><strong>logs命令</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># 从 pod 返回日志快照</span><br><span class="line">kubectl logs &lt;pod-name&gt;</span><br><span class="line"># 从 pod &lt;pod-name&gt; 开始流式传输日志。这类似于 &#39;tail -f&#39; Linux 命令。</span><br><span class="line">kubectl logs -f &lt;pod-name&gt;</span><br></pre></td></tr></table></figure>

<p><strong>格式化输出</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">将pod信息格式化输出到一个yaml文件 </span><br><span class="line">kubectl get pod web-pod-13je7 -o yaml</span><br></pre></td></tr></table></figure>

<p><strong>强制删除pod</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">强制删除一个pod </span><br><span class="line">--force --grace-period&#x3D;0</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="article-footer">
      <a data-url="http://codercheng.cn/2021/03/31/k8s/" data-id="cko3snvx60013i8uo80hm3xwu" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-Docker学习笔记" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/03/18/Docker%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="article-date">
  <time datetime="2021-03-18T07:33:27.080Z" itemprop="datePublished">2021-03-18</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2021/03/18/Docker%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">Docker学习笔记</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <pre><code>Docker学习笔记</code></pre><p>当人们说“Docker”时，他们通常是指 Docker Engine，它是一个客户端 - 服务器应用程序，由 Docker守护进程、一个REST API指定与守护进程交互的接口、和一个命令行接口（CLI）与守护进程通信（通过封装REST API）。Docker Engine 从 CLI 中接受docker 命令，例如 docker run 、docker ps 来列出正在运行的容器、docker images 来列出镜像，等等。</p>
<p><strong>docker</strong> <strong>基本组成</strong></p>
<p>docker主机(Host)：安装了Docker程序的机器（Docker直接安装在操作系统之上）；</p>
<p>docker仓库(Registry)：用来保存各种打包好的软件镜像；仓库分为公有仓库和私有仓库。(很类似maven)</p>
<p>docker镜像(Images)：软件打包好的镜像；放在docker仓库中；</p>
<p>docker容器(Container)：镜像启动后的实例称为一个容器；容器是独立运行的一个或一组应用</p>
<p><strong>docker 与操作系统比较</strong></p>
<p>docker是一种轻量级的虚拟化方式</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/18/150851-563512.png" alt="image-20210318150849177"></p>
<p> Docker常用命令</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/18/161605-357589.png" alt="image-20210318151000222"></p>
<p><strong>images命令</strong></p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker images </span><br><span class="line">docker image ls</span><br></pre></td></tr></table></figure>

<p><strong>save命令</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">mkdir -p /data </span><br><span class="line">cd /data </span><br><span class="line">docker save tomcat:9.0.20-jre8-alpine -o tomcat9.tar </span><br><span class="line">docker save tomcat:9.0.20-jre8-slim &gt; tomcat9.slim.tar</span><br></pre></td></tr></table></figure>

<p><strong>inspect命令</strong></p>
<ul>
<li>通过 docker inspect 命令，我们可以获取镜像的详细信息，其中，包括创建者，各层的数字摘要等。</li>
</ul>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker inspect tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre8</span><span class="literal">-alpine</span></span><br><span class="line">docker inspect <span class="operator">-f</span> &#123;&#123;<span class="string">".Size"</span>&#125;&#125; tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre8</span><span class="literal">-alpine</span></span><br></pre></td></tr></table></figure>

<p><strong>history命令</strong></p>
<ul>
<li>从前面的命令中，我们了解到，一个镜像是由多个层组成的，那么，我们要如何知道各个层的具体内容呢？</li>
</ul>
<p>通过 docker history命令，可以列出各个层的创建信息，例如：查看 tomcat:9.0.20-jre8-alpine的各层信息</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker history tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre8</span><span class="literal">-alpine</span></span><br></pre></td></tr></table></figure>

<p><strong>tag命令</strong></p>
<ul>
<li>标记本地镜像，将其归入某一仓库</li>
</ul>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker tag tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre8</span><span class="literal">-alpine</span> lagou/tomcat:<span class="number">9</span></span><br></pre></td></tr></table></figure>

<p><strong>rmi命令</strong></p>
<p>  <strong>常用参数</strong></p>
<ul>
<li>-f, -force : 强制删除镜像，即便有容器引用该镜像；</li>
<li>-no-prune : 不要删除未带标签的父镜像；</li>
</ul>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker rmi tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre8</span><span class="literal">-alpine</span> </span><br><span class="line">docker image rm tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre8</span><span class="literal">-alpine</span></span><br></pre></td></tr></table></figure>

<p><strong>清理镜像</strong></p>
<p>我们在使用 Docker 一段时间后，系统一般都会残存一些临时的、没有被使用的镜像文件，可以通过以下命令进行清理。执行完命令后，还是告诉我们释放了多少存储空间！</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker image prune</span><br></pre></td></tr></table></figure>

<p>​                                                                             <strong>Docker容器（container）</strong></p>
<p><strong>容器是镜像的运行时实例</strong></p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/18/151858-535527.png" alt="image-20210318151857629"></p>
<p><strong>新建并启动容器</strong></p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run [<span class="type">OPTIONS</span>] IMAGE [<span class="type">COMMAND</span>] [<span class="type">ARG...</span>]</span><br></pre></td></tr></table></figure>

<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run <span class="literal">-it</span> -<span class="literal">-rm</span> <span class="literal">-p</span> <span class="number">8080</span>:<span class="number">8080</span> tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre8</span><span class="literal">-alpine</span></span><br></pre></td></tr></table></figure>

<p><strong>docker run</strong>命令常用参数比较多，这里仅仅列出开发岗常用参数，请小伙伴们自行查找资料获得更多参数信息</p>
<p><strong>-d, –detach=false:</strong> 后台运行容器，并返回容器ID</p>
<p><strong>-i, –interactive=false:</strong> 以交互模式运行容器，通常与 -t 同时使用</p>
<p><strong>-P, –publish-all=false:</strong> 随机端口映射，容器内部端口随机映射到主机的端口。<strong>不推荐各位小伙伴使用该参数</strong></p>
<p><strong>-p, –publish=[]:</strong> 指定端口映射，格式为：主机(宿主)端口容器端口，推荐各位小伙伴们使用**</p>
<p><strong>-t, –tty=false:</strong> 为容器重新分配一个伪输入终端，通常与 -i 同时使用</p>
<p><strong>–name=”nginx-lb”:</strong> 为容器指定一个名称</p>
<p><strong>-h , –hostname=”laosiji”:</strong> 指定容器的hostname</p>
<p><strong>-e , –env=[]:</strong> 设置环境变量，容器中可以使用该环境变量</p>
<p><strong>–net=”bridge”:</strong> 指定容器的网络连接类型，支持 bridge/host/none/container: 四种类型</p>
<p><strong>–link=[]:</strong> 添加链接到另一个容器；<strong>不推荐各位小伙伴使用该参数</strong></p>
<p><strong>-v, –volume :</strong> 绑定一个卷</p>
<p><strong>–privileged=false:</strong> 指定容器是否为特权容器，特权容器拥有所有的capabilities </p>
<p><strong>–restart=no</strong>：指定容器停止后的重启策略</p>
<p>no：容器退出时不重启 </p>
<p>on-failure：容器故障退出（返回值非零）时重启 </p>
<p>always：容器退出时总是重启,<strong>推荐各位小伙伴们使用</strong> </p>
<p><strong>–rm=false:</strong> 指定容器停止后自动删除容器,<strong>不能以</strong>docker run -d<strong>启动的容器</strong></p>
<p><strong>容器日志</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker logs [OPTIONS] CONTAINER</span><br></pre></td></tr></table></figure>

<p><strong>-f :</strong> 跟踪日志输出</p>
<p><strong>–tail :</strong>仅列出最新N条容器日志</p>
<p><strong>删除容器</strong></p>
<p><strong>docker rm</strong> <strong>：</strong>删除一个或多个容器。docker rm命令只能删除处于终止或退出状态的容器，并不能删除还处于运行状态容器</p>
<p><strong>-f :</strong>通过 SIGKILL 信号强制删除一个运行中的容器。</p>
<p><strong>-l :</strong>移除容器间的网络连接，而非容器本身。</p>
<p><strong>-v :</strong>删除与容器关联的卷。</p>
<p><strong>列出容器</strong></p>
<p>docker ps [OPTIONS] </p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">docker run <span class="literal">-itd</span> -<span class="literal">-name</span> tomcat9 <span class="literal">-p</span> <span class="number">8080</span>:<span class="number">8080</span> tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre8</span><span class="literal">-alpine</span> </span><br><span class="line">查看运行中的容器 </span><br><span class="line">docker ps tomcat9 </span><br><span class="line">查看所有容器 </span><br><span class="line">docker ps <span class="literal">-a</span> tomcat9</span><br></pre></td></tr></table></figure>

<p><strong>启动、重启、终止容器</strong></p>
<p><strong>docker start</strong> :启动一个或多个已经被停止的容器</p>
<p><strong>docker stop</strong> :停止一个运行中的容器</p>
<p><strong>docker restart</strong> :重启容器</p>
<p><strong>进入容器</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker exec [OPTIONS] CONTAINER COMMAND [ARG...]</span><br></pre></td></tr></table></figure>

<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">有bash命令的linux系统：例如centos</span><br><span class="line">docker run <span class="literal">-it</span> -<span class="literal">-name</span> tomcat9.<span class="number">1</span> <span class="literal">-p</span> <span class="number">8080</span>:<span class="number">8080</span> tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre8</span><span class="literal">-slim</span></span><br><span class="line">docker exec <span class="literal">-it</span> tomcat9.<span class="number">1</span> /bin/bash </span><br><span class="line">没有bash命令的linux系统：例如alpine系统 </span><br><span class="line">docker run <span class="literal">-it</span> -<span class="literal">-name</span> tomcat9.<span class="number">2</span> <span class="literal">-p</span> <span class="number">8081</span>:<span class="number">8080</span> tomcat:<span class="number">9.0</span>.<span class="number">20</span><span class="literal">-jre8</span><span class="literal">-alpine</span> </span><br><span class="line">docker exec <span class="literal">-it</span> tomcat9.<span class="number">2</span> sh</span><br></pre></td></tr></table></figure>

<p><strong>查看容器</strong></p>
<p><strong>docker inspect :</strong> 获取容器/镜像的元数据。</p>
<p> 语法 </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker inspect [OPTIONS] NAME|ID [NAME|ID...]</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker run -it --name tomcat9 -p 8081:8080 tomcat:9.0.20-jre8-alpine </span><br><span class="line">docker inspect tomcat9</span><br></pre></td></tr></table></figure>

<p>常用参数</p>
<p><strong>-f :</strong>指定返回值的模板文件。</p>
<p><strong>-s :</strong>显示总的文件大小。</p>
<p><strong>–type :</strong>为指定类型返回JSON。</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/18/153201-770904.png" alt="image-20210318153201331"></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://codercheng.cn/2021/03/18/Docker%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" data-id="cko3snvw80002i8uo2t6d3cvp" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-ElasticSearch学习笔记" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/03/11/ElasticSearch%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="article-date">
  <time datetime="2021-03-11T10:02:47.678Z" itemprop="datePublished">2021-03-11</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2021/03/11/ElasticSearch%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">ElasticSearch学习笔记</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <pre><code>ElasticSearch学习笔记</code></pre><ul>
<li><p>概念</p>
<p> Elaticsearch简称为ES,是一个开源的可扩展的分布式的<strong>全文检索引擎</strong>，它可以近乎实时的存储、检索数据。本身扩展性很好，可扩展到上百台服务器，处理<strong>PB</strong>级别的数据。ES使用Java开发并使用Lucene作为其核心来实现索引和搜索的功能，但是它通过简单的<strong>RestfulAPI</strong>和<strong>javaAPI</strong>来隐藏Lucene的复杂性，从而让全文搜索变得简单。</p>
</li>
<li><p>功能</p>
<ol>
<li><p>分布式的搜索引擎</p>
<p>分布式：Elasticsearch自动将海量数据分散到多台服务器上去存储和检索</p>
<p>搜索：百度、谷歌，站内搜索</p>
</li>
</ol>
</li>
</ul>
<p>​           2.  全文检索</p>
<p>​              提供模糊搜索等自动度很高的查询方式，并进行相关性排名，高亮等功能</p>
<p>​           3. 数据分析引擎（分组聚合）  </p>
<p>​         电商网站，最近一周笔记本电脑这种商品销量排名top10的商家有哪些？新闻网站，最近1个月访问量排名top3的新闻板块是哪些.</p>
<p>​          4 . 对海量数据进行近实时的处理 </p>
<p>​      海量数据的处理：因为是分布式架构，Elasticsearch可以采用大量的服务器去存储和检索数据，自然而然就可以实现海量数据的处理近实时：Elasticsearch可以实现秒级别的数据搜索和分析.</p>
<p>​     使用实例</p>
<p>   创建索引</p>
<pre><code><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">PUT my_index</span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">"settings"</span>: &#123;</span><br><span class="line">      <span class="string">"属性名"</span>：<span class="string">"属性值"</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></code></pre><p>判断索引是否存在</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">HEAD &#x2F;my_index</span><br></pre></td></tr></table></figure>

<p> 查看索引</p>
 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;my_index</span><br></pre></td></tr></table></figure>

<p>  批量查看索引</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;索引名称1，索引名称2</span><br></pre></td></tr></table></figure>

<p> 查看所有索引</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET _all</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;_cat&#x2F;indices?v</span><br></pre></td></tr></table></figure>



<p> 删除索引库</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DELETE &#x2F;my_indx</span><br></pre></td></tr></table></figure>



<p><strong>字段映射</strong></p>
 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">PUT &#x2F;索引库名&#x2F;_mapping</span><br><span class="line">&#123;</span><br><span class="line"> &quot;properties&quot;:&#123;</span><br><span class="line">    &quot;字段名&quot;&#123;</span><br><span class="line">    &quot;type&quot;:&quot;类型&quot;,</span><br><span class="line">    &quot;index&quot;:true,</span><br><span class="line">    &quot;store&quot;:true,</span><br><span class="line">    &quot;analyzer&quot;:&quot;分词器&quot;</span><br><span class="line">   &#125;</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>eg:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">PUT /lagou-company-index</span><br><span class="line">PUT /lagou-company-index/_mapping</span><br><span class="line">&#123;</span><br><span class="line">  <span class="attr">"properties"</span>: &#123;</span><br><span class="line">    <span class="attr">"name"</span>: &#123;</span><br><span class="line">      <span class="attr">"type"</span>: <span class="string">"text"</span>,</span><br><span class="line">      <span class="attr">"analyzer"</span>: <span class="string">"ik_max_word"</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="attr">"job"</span>: &#123;</span><br><span class="line">      <span class="attr">"type"</span>: <span class="string">"text"</span>,</span><br><span class="line">      <span class="attr">"analyzer"</span>: <span class="string">"ik_max_word"</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="attr">"logo"</span>: &#123;</span><br><span class="line">      <span class="attr">"type"</span>: <span class="string">"keyword"</span>,</span><br><span class="line">      <span class="attr">"index"</span>: <span class="literal">false</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="attr">"payment"</span>: &#123;</span><br><span class="line">      <span class="attr">"type"</span>: <span class="string">"float"</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>  <strong>文档的增删改查及局部更新</strong></p>
<p>文档，即索引库中的数据，会根据规则创建索引，将来用于搜索。可以类比做数据库中的一行数据</p>
<p>语法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;索引名称&#x2F;_doc </span><br><span class="line">&#123; </span><br><span class="line">&quot;field&quot;:&quot;value&quot; </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lagou-company-index&#x2F;_doc&#x2F;1</span><br><span class="line">&#123;</span><br><span class="line">  &quot;name&quot;:&quot;百度&quot;,</span><br><span class="line">  &quot;job&quot;:&quot;小度用户运营经理&quot;,</span><br><span class="line">  &quot;payment&quot;:&quot;30000&quot;,</span><br><span class="line">&quot;logo&quot;:&quot;http:&#x2F;&#x2F;www.lgstatic.com&#x2F;thubnail_120x120&#x2F;i&#x2F;image&#x2F;M00&#x2F;21&#x2F;3E&#x2F;CgpFT1kVdzeAJNbUAABJB7x9sm8374.png&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>查看单个文档</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;索引名称&#x2F;_doc&#x2F;&#123;id&#125;</span><br></pre></td></tr></table></figure>

<p><strong>查看所有文档</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;索引名称&#x2F;_search </span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;:&#123; </span><br><span class="line">  &quot;match_all&quot;: &#123; </span><br><span class="line">   &#125;</span><br><span class="line">  &#125; </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>更新文档</strong></p>
<p>  局部更新</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lagou-company-index&#x2F;_update&#x2F;1</span><br><span class="line">&#123;</span><br><span class="line">  &quot;doc&quot;:&#123;</span><br><span class="line">    &quot;logo&quot;:&quot;1111&quot; </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>  全部更新</p>
<p>​      新增请求 改为PUT  就是修改了</p>
<p>​        DSL语句</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lagou-company-index&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_all&quot;: &#123;&#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lagou-company-index&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &quot;百度&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>match 类型查询，会把查询条件进行分词，然后进行查询,多个词条之间是or的关系</p>
<p><strong>短语搜索</strong> (match phrase query)</p>
<p>   match_phrase 查询用来对一个字段进行短语查询，可以指定 analyzer、slop移动因子</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lagou-company-index&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;match_phrase&quot;: &#123;</span><br><span class="line">      &quot;name&quot;:&#123;</span><br><span class="line">         &quot;query&quot;: &quot;百 12&quot;,</span><br><span class="line">         &quot;slop&quot;: 2  </span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p><strong>query_string</strong> <strong>查询</strong></p>
<p>Query String Query提供了无需指定某字段而对文档全文进行匹配查询的一个高级查询,同时可以指定在哪些字段上进行匹配。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">GET &#x2F;lagou-company-index&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;query_string&quot;: &#123;</span><br><span class="line">      &quot;query&quot;: &quot;30000&quot;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p><strong>词条级搜索</strong> <strong>(term-level queries)</strong></p>
<p>可以使用<strong>term-level queries</strong>根据结构化数据中的精确值查找文档。结构化数据的值包括日期范围、IP地址、价格或产品ID。</p>
<p>与全文查询不同，term-level queries不分析搜索词。相反，词条与存储在字段级别中的术语完全匹配。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">POST &#x2F;lagou-company-index&#x2F;_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;query&quot;: &#123;</span><br><span class="line">    &quot;term&quot;: &#123;</span><br><span class="line">      &quot;name&quot;: &#123;</span><br><span class="line">        &quot;value&quot;: &quot;12&quot;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>








      
    </div>
    <footer class="article-footer">
      <a data-url="http://codercheng.cn/2021/03/11/ElasticSearch%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" data-id="cko3snvw90003i8uo0oaw27hc" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-基于RocketMQ设计秒杀。" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/03/03/%E5%9F%BA%E4%BA%8ERocketMQ%E8%AE%BE%E8%AE%A1%E7%A7%92%E6%9D%80%E3%80%82/" class="article-date">
  <time datetime="2021-03-03T06:04:56.147Z" itemprop="datePublished">2021-03-03</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E4%BD%9C%E4%B8%9A/">作业</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2021/03/03/%E5%9F%BA%E4%BA%8ERocketMQ%E8%AE%BE%E8%AE%A1%E7%A7%92%E6%9D%80%E3%80%82/">基于RocketMQ设计秒杀。</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>​                基于RocketMQ设计秒杀作业   </p>
<p>整体思路:</p>
<p>1 使用redis 进行获取锁</p>
<p>2 获取锁后 调用RocketMQ 发送订单消息</p>
<p>​        -   使用redis 进行订单数量的累加 同时 redis 记录订单id</p>
<p>3    rocketmq 收到下单消息后 进行下单操作  等待用户支付 。</p>
<p>4    向RocketMQ 发送一条延时订单 检查的消息</p>
<p>5  延时消息到期后 </p>
<p>​        检查订单状态   如果支付  不进行有效订单的数量的操作</p>
<p>​          未完成支付  有效订单数量减少</p>
<p> 步骤 </p>
<ul>
<li>首先 先新建springboot 项目 整合RockertMQ +Redis  </li>
</ul>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/03/135501-574526.png" alt="image-20210303135500684"></p>
<p>​      </p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/03/135632-29641.png" alt="image-20210303135630504"></p>
<p>​     redis 本地  正常 下单请求会有 orderSize 变成100 同时 会有100条订单记录</p>
<p>​        使用线程池默认并发500下单 操作  </p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/03/135728-970039.png" alt="image-20210303135728017"></p>
<p>​          本地访问   <a href="http://localhost:8080/order" target="_blank" rel="noopener">http://localhost:8080/order</a></p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/03/135914-971745.png" alt="image-20210303135913602"></p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/03/140229-584742.png" alt="image-20210303140229125"></p>
<p>​          等待超时队列到期   不支付   订单达到100  清除 未支付的订单 数量</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/03/140914-117758.png" alt="image-20210303140708775"></p>
<p>​         可以看到 有效订单数量减少为0 </p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/03/140528-258817.png" alt="image-20210303140527850"></p>
<p>此时    用户可以继续下单操作</p>
<p><img src="https://gitee.com/adc123321/blog_img/raw/master/image/202103/03/140829-493201.png" alt="image-20210303140818437"></p>
<p> 这样就保证了库存不超卖的情况。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://codercheng.cn/2021/03/03/%E5%9F%BA%E4%BA%8ERocketMQ%E8%AE%BE%E8%AE%A1%E7%A7%92%E6%9D%80%E3%80%82/" data-id="cko3snvxb001fi8uo8z3dat20" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  


  <nav id="page-nav">
    
    <a class="extend prev" rel="prev" href="/">&amp;laquo; 上一页</a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/">3</a><a class="page-number" href="/page/4/">4</a><span class="space">&hellip;</span><a class="page-number" href="/page/6/">6</a><a class="extend next" rel="next" href="/page/3/">下一页 &amp;raquo;</a>
  </nav>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/MySql/">MySql</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Netty/">Netty</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/SpringBoot/">SpringBoot</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/SpringCloud/">SpringCloud</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/SpringMVC/">SpringMVC</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Tomcat/">Tomcat</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Zookeeper/">Zookeeper</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%BD%9C%E4%B8%9A/">作业</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%88%86%E5%B8%83%E5%BC%8F%E8%B0%83%E5%BA%A6/">分布式调度</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%A1%86%E6%9E%B6/">框架</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%9F%A5%E8%AF%86/">知识</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">设计模式</a></li></ul>
    </div>
  </div>


  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2024/08/">八月 2024</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/09/">九月 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/08/">八月 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/04/">四月 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/02/">二月 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/11/">十一月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/06/">六月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/05/">五月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/04/">四月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/03/">三月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/02/">二月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/01/">一月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/12/">十二月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/11/">十一月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/10/">十月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/09/">九月 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/08/">八月 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2024/08/28/CentOS%E5%86%85%E5%AD%98cpu%E6%8E%92%E6%9F%A5/">CentOS内存cpu排查</a>
          </li>
        
          <li>
            <a href="/2022/09/22/Linux%20%E6%9F%A5%E7%9C%8B%E6%97%A5%E5%BF%97%E5%91%BD%E4%BB%A4/">Linux 查看日志命令</a>
          </li>
        
          <li>
            <a href="/2022/08/30/dubbo%20%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/">dubbo 常见问题</a>
          </li>
        
          <li>
            <a href="/2022/04/26/1%20%E6%BA%90%E7%A0%81%E7%AC%94%E8%AE%B0/">1 源码笔记</a>
          </li>
        
          <li>
            <a href="/2022/02/24/jvisualVM%20%E4%BD%BF%E7%94%A8%E7%AC%94%E8%AE%B0/">jvisualVM 使用笔记</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2024 CoderCheng<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//code.jquery.com/jquery-2.0.3.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>




  </div>
</body>
</html>